package com.hzlj.position.config.service;

import com.google.common.util.concurrent.RateLimiter;
import com.hzlj.position.config.common.dto.common.TaskConfig;
import com.hzlj.position.config.common.dto.wdConfig.WdConfigQueryResultDTO;
import com.hzlj.position.config.rest.wd.WdLocateRest;
import lombok.Data;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * 定位-腕带配置表(WdConfig)表服务接口
 *
 * @author makejava
 * @date 2024-07-18 15:34:28
 */
public interface WdConfigService {
    /**
     * 查询列表：不分页
     */
    List<WdConfigQueryResultDTO> listWdConfig();

    WdTaskConfig taskConfig(String jgCode, String channel);

    List<String> channels();

    List<WdTaskConfig> taskConfigs();

    @Data
    class WdTaskConfig extends TaskConfig {
        private WdLocateRest wdLocateRest;
        private WdConfigQueryResultDTO config;
        private ScheduledExecutorService delayQueue = null;

        public WdTaskConfig(WdLocateRest wdLocateRest,
                            WdConfigQueryResultDTO config,
                            RateLimiter rateLimiter) {
            this.wdLocateRest = wdLocateRest;
            this.config = config;
            if (config.getRequestDelaySeconds() > 0) {
                delayQueue = Executors.newScheduledThreadPool(config.getRequestDelayQueueSize());
            }
            super.setRateLimiter(rateLimiter);
        }
    }
}
